package com.lnsf.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.lnsf.entity.Department;
import com.lnsf.service.DeptService;


@Controller
public class DeptController {
	
	@Autowired
	private DeptService deptService;
	
	/*@RequestMapping("/getAllDepartment")
	public String getAllDepartment() {
		List<Department> Departments = deptService.getAllDepartment();
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("Departments", Departments);
		
		
		return "success";
	}
	
	
	@RequestMapping("/getDepartmentById/{id}")
	public ModelAndView getDepartmentById(@PathVariable("id")int deptno) {
		System.out.println("Department:"+deptno);
		
		Department Department = deptService.getDepartmentById(deptno);
		System.out.println(Department);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("Department", Department);
		modelAndView.setViewName("success");
		
		return modelAndView;
	}
	
	
	
	 * 增加修改先获取
	 
	@RequestMapping("/toDetails/{id}")
	public String toDetails(@PathVariable(value="id",required=false) int deptno , Map<String, Object> map){
		Department department = deptService.getDepartmentById(deptno);
		map.put("DepartmentInfo", department);
		return "addEmp";
	}
	
	
	@RequestMapping("/insertDepartment")
	public ModelAndView insertDepartment(Department Department) {
		
		deptService.addDepartment(Department);
		ModelAndView modelAndView = new ModelAndView();
		
		modelAndView.setView(new RedirectView("getAllDepartment"));
		
		return modelAndView;
	}*/
	
	
	
	
	
	
	
	
	
	public DeptService getdeptService() {
		return deptService;
	}
	public void setdeptService(DeptService deptService) {
		this.deptService = deptService;
	}
}
